package com.wikidot.designpatterns.builder;

import java.util.HashMap;

/**
 * Concrete builder. The implemented methods are defining the construction
 * process. Each concrete builder can define own specific construction but the
 * product will always be the same.
 */
class CompanyOneLabelBuilder extends LabelBuilder {
	public void setDescription(String description) {
		this.label.setDescription(description);
	}

	/**
	 * Label ID is constructed as 3 groups of 3 characters. The separator is
	 * space.
	 */
	public void setId(String id) {
		if ((id.length() % 3) != 0) {
			System.out.println("Invalid ID: " + id);
		}
		StringBuilder targetId = new StringBuilder();
		for (int i = 0; i < id.length(); i += 3) {
			targetId.append(id.substring(i, i + 3));
			targetId.append(" ");
		}
		this.label.setId(targetId.toString().trim());
	}

	/**
	 * Tags have specific code. The rest of tags which are unknown are left
	 * unchanged. The mapping is defined by MAPPING attribute.
	 */
	public void setTag(String tag) {
		if (MAPPING.containsKey(tag.toLowerCase())) {
			this.label.setTag(MAPPING.get(tag.toLowerCase()));
		} else {
			this.label.setTag(tag);
		}
	}

	private static HashMap<String, String> MAPPING = new HashMap<String, String>();
	{
		MAPPING.put("fragile", "F");
		MAPPING.put("handle with care", "C");
	}
}
